package cdu.javaendwork.service.Impl.User;

import cdu.javaendwork.dao.Universal;
import cdu.javaendwork.dao.impl.UniversalImpl;
import cdu.javaendwork.model.sqlModel.User;
import cdu.javaendwork.service.Interface.User.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {

    Universal universal = new UniversalImpl();

    // 添加用户
    @Override
    public boolean insert(String username, String password, String photo, String userprofile, String phone, int status) {

        return universal.insert("User" , username,password,photo,userprofile,phone,status) == 1;
    }

    // 通用id修改用户
    @Override
    public boolean update(int id, String username, String password, String photo, String userprofile, String phone, int status) {

        return universal.updateById("User",id,username,password,photo,userprofile,phone,status)==1;
    }

    // 单查用户信息
    @Override
    public User findById(int id) {

        return universal.getById("User",id);
    }

    // 分页查询普通用户信息
    @Override
    public List<User> Userlimit(int pageIndex, int pageSize) {

        return universal.filterLimit("User" , "status=1 or status=3" , pageIndex,pageSize);
    }

    // 通过用户名模糊查询并分页普通用户信息
    @Override
    public List<User> filterByUsernameAndStatusLimit(String username, int status,int pageIndex, int pageSize) {

        return universal.filterLimit("User","(status="+status+") and username like '%" + username + "%'",pageIndex,pageSize);
    }

    // 分页查询管理员用户信息
    @Override
    public List<User> AdminLimit(int pageIndex, int pageSize) {

        return universal.filterLimit("User","status=2",pageIndex,pageSize);
    }

    // 通过用户名模糊查询并分页管理员用户信息
    @Override
    public List<User> AdminFilterByUsernameLimit(String where, int pageIndex, int pageSize) {

        return universal.filterLimit("User","status=2 and username like '%" + where + "%'",pageIndex,pageSize);
    }
}
